package com.hema.auction.widget.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hema.auction.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * author by john
 * 首页底部自定义tabview
 */
public class TabView extends RelativeLayout {

    @BindView(R.id.iv_icon)
    ImageView ivIcon;
    @BindView(R.id.tv_title)
    TextView tvTab;
    @BindView(R.id.tv_new)
    TextView tvNum;

    public TabView(Context context, AttributeSet attrs) {
        super(context, attrs);
        ButterKnife.bind(this,LayoutInflater.from(context).inflate(R.layout.layout_tab, this));
    }

    /**
     * 设置tab名称及图标
     *
     * @param name
     * @param resId
     */
    public void setTextAndDrawableTop(int name, int resId) {
        tvTab.setText(name);
        ivIcon.setImageResource(resId);
    }

    /**
     * 设置当前tab是否可点
     *
     * @param enabled
     */
    public void setTabCheck(boolean enabled) {
//        setEnabled(enabled);
//        tvTab.setEnabled(enabled);
        ivIcon.setEnabled(!enabled);
        if (enabled) {
            tvTab.setTextColor(getResources().getColor(R.color.tab_select));
        } else {
            tvTab.setTextColor(getResources().getColor(R.color.tab_normal));
        }
    }

    /**
     * 设置未读消息数量
     *
     * @param num
     */
    public void setNewNum(int num) {
        if (num > 0) {
            tvNum.setVisibility(View.VISIBLE);
            if (num < 100)
                tvNum.setText(String.valueOf(num));
            else
                tvNum.setText("N");
        } else {
            tvNum.setVisibility(View.GONE);
        }
    }

}
